import { CallSprite } from "./CallSprite";
import { Language } from "../../../../../extend/language/Language";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FaceMcRender } from "./FaceMcRender";
import { ListEvent } from "../../../../../fl/events/ListEvent";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ResManager } from "../../../../common/ResManager";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Cache } from "../../../cache/Cache";
import { MuiEvent } from "../../../../../com/mui/events/MuiEvent";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { StringUtil } from "../../../../../mx/utils/StringUtil";
import { Global } from "../../../../../com/gengine/global/Global";
import { GTabBar } from "../../../../../com/mui/controls/GTabBar";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
type int = number;
//class FacePanel
    
    export  class FacePanel extends CallSprite
    {
        constructor()
        {
            super();
            this._loadTips = Language.getString(40669);
            this._notVipTips = Language.getString(40696);
            this._dicFaceMcNumber = new Map<any, any> /* flash.utils.Dictionary */();
            this._classDict = new Map<any, any> /* flash.utils.Dictionary */();
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=ResouceConst.getScaleBitmap("ToolTipBg");
            loc1.width = 310;
            loc1.height = 185;
            this.addChild(loc1);
            ObjCreate.createBg(10, 155, 299, 1, this, "SeptalLine");
            this._tabBarData = [{"name": Language.getString(40697), "label": Language.getString(40697)}, {"name": Language.getString(40698), "label": Language.getString(40698)}];
            this._tabBar = ObjCreate.createGTabBar(8, 157, this._tabBarData, 62, 22, this, this.onTabBarChange);
            this._tabBar.buttonStyleName = "TextButton2";
            this._tfNotHaveFace = ObjCreate.createTextField(this._loadTips, 30, 70, 240, 20, null, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat1));
            this._normalPanel = new Object /* flash.display.Sprite */();
            this.addChild(this._normalPanel);
            this._vipPanel = new Object /* flash.display.Sprite */();
            this._vipPanel.visible = false;
            this.addChild(this._vipPanel);
            this._faceList = ObjCreate.createTileList(11, 8, 304, 154, this._vipPanel);
            this._faceList.setStyle("cellRenderer", FaceMcRender);
            this._faceList.columnWidth = 60;
            this._faceList.rowHeight = 50;
            this._faceList.addEventListener(ListEvent.ITEM_CLICK, this.choseVIPFaceHandler);
            this._pageSelecter = ObjCreate.createPageSelecter(220, 160, this._vipPanel);
            this._pageSelecter.maxPage = 2;
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onPageChangeHandler);
            this.createNormal();
            this.createVIP();
            this.addChild(this._tfNotHaveFace);
            return;
        }

        /* internal  */onPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageSelecter.currentPage;
            this._faceList.dataProvider = new DataProvider(this._classDict[loc1]);
            return;
        }

        /* internal  */createNormal(): void
        {
            if (ResManager.instance.isFaceLoaded) 
            {
                this.addFace();
            }
            else 
            {
                ResManager.instance.registerFace(this.addFace);
            }
            this.layOut();
            return;
        }

        /* internal  */addFace(): void
        {
            var loc2=null;
            var loc1=1;
            while (loc1 <= 72) 
            {
                loc2 = GlobalClass.getInstance("a" + (loc1 - 1)) as Object /* flash.display.MovieClip */;
                loc2.x = 5 + 25 * (loc1 - 1) % 12;
                loc2.y = 5 + 25 * Math.floor((loc1 - 1) / 12);
                loc2.mouseEnabled = true;
                loc2.buttonMode = true;
                this._normalPanel.addChild(loc2);
                loc2.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.selectHandler);
                loc2.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.selectHandler);
                loc2.addEventListener(flash.events.MouseEvent.CLICK, this.choseFaceHandler);
                this._dicFaceMcNumber[loc2] = loc1;
                ++loc1;
            }
            this.layOut();
            return;
        }

        /* internal  */createVIP(): void
        {
            var loc1=null;
            this._maskSp = new Object /* flash.display.Sprite */();
            loc1 = new Object /* flash.display.Bitmap */();
            loc1.x = 3;
            loc1.y = 3;
            loc1.bitmapData = new Object /* flash.display.BitmapData */(304, 154, true, 1728053247);
            loc1.visible = false;
            this._maskSp.addChild(loc1);
            this.addChild(this._maskSp);
            if (ResManager.instance.isFaceVIPLoaded) 
            {
                this.addFaceVIP1();
            }
            else 
            {
                ResManager.instance.registerFaceVIP(this.addFaceVIP1);
            }
            if (ResManager.instance.isFaceVIP2Loaded) 
            {
                this.addFaceVIP2();
            }
            else 
            {
                ResManager.instance.registerFaceVIP2(this.addFaceVIP2);
            }
            this.layOut();
            return;
        }

        /* internal  */addFaceVIP1(): void
        {
            this.addFaceVIP(1, "b", 14);
            return;
        }

        /* internal  */addFaceVIP2(): void
        {
            this.addFaceVIP(2, "c", 15);
            return;
        }

        /* internal  */addFaceVIP(arg1: int, arg2: string, arg3: int): void
        {
            var loc2=null;
            var loc1=new Array<any>();
            var loc3=1;
            while (loc3 <= arg3) 
            {
                loc2 = GlobalClass.getInstance(arg2 + (loc3 - 1)) as Object /* flash.display.MovieClip */;
                loc1.push(arg2 + (loc3 - 1));
                this._dicFaceMcNumber[loc2] = arg2 + loc3;
                ++loc3;
            }
            this._classDict[arg1] = loc1;
            return;
        }

        public layOut(): void
        {
            this._tfNotHaveFace.visible = false;
            this._normalPanel.visible = false;
            this._vipPanel.visible = false;
            var loc1=this._tabBar.selectedIndex;
            if (loc1 != 0) 
            {
                if (loc1 == 1) 
                {
                    if (Cache.instance.vip.isVIP) 
                    {
                        if (ResManager.instance.isFaceLoaded) 
                        {
                            this._vipPanel.visible = true;
                            this.onPageChangeHandler(null);
                        }
                        else 
                        {
                            this._tfNotHaveFace.text = this._loadTips;
                            this._tfNotHaveFace.visible = true;
                        }
                    }
                    else 
                    {
                        this._tfNotHaveFace.text = this._notVipTips;
                        this._tfNotHaveFace.visible = true;
                    }
                }
            }
            else if (ResManager.instance.isFaceLoaded) 
            {
                this._normalPanel.visible = true;
            }
            else 
            {
                this._tfNotHaveFace.text = this._loadTips;
                this._tfNotHaveFace.visible = true;
            }
            return;
        }

        /* internal  */onTabBarChange(arg1: MuiEvent): void
        {
            this.layOut();
            return;
        }

        /* internal  */selectHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as Object /* flash.display.MovieClip */;
            if (arg1.type == flash.events.MouseEvent.MOUSE_OVER) 
            {
                loc1.filters = [FilterConst.itemChooseFilter];
            }
            if (arg1.type == flash.events.MouseEvent.MOUSE_OUT) 
            {
                loc1.filters = [];
            }
            return;
        }

        /* internal  */choseFaceHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            callAll(this._dicFaceMcNumber[arg1.currentTarget as Object /* flash.display.MovieClip */]);
            return;
        }

        /* internal  */choseVIPFaceHandler(arg1: ListEvent): void
        {
            var loc1=arg1.item.data;
            loc1 = loc1.substring(0, 1) + (int(StringUtil.trim(loc1.substring(1))) + 1);
            callAll(loc1);
            return;
        }

        public /* override */ set visible(arg1: Boolean)
        {
            var loc1=undefined;
            super.visible = arg1;
            var loc2=0;
            var loc3=this._dicFaceMcNumber;
            for (loc1 in loc3) 
            {
                if (!(loc1 is flash.display.MovieClip)) 
                {
                    continue;
                }
                if (arg1 && Global.stage.contains(this)) 
                {
                    (loc1 as Object /* flash.display.MovieClip */).play();
                    continue;
                }
                (loc1 as Object /* flash.display.MovieClip */).stop();
            }
            return;
        }

        public stopAllFace(): void
        {
            var loc1=undefined;
            var loc2=0;
            var loc3=this._dicFaceMcNumber;
            for (loc1 in loc3) 
            {
                if (!(loc1 is flash.display.MovieClip)) 
                {
                    continue;
                }
                (loc1 as Object /* flash.display.MovieClip */).stop();
            }
            return;
        }

        public startAllFace(): void
        {
            var loc1=undefined;
            var loc2=0;
            var loc3=this._dicFaceMcNumber;
            for (loc1 in loc3) 
            {
                if (!(loc1 is flash.display.MovieClip)) 
                {
                    continue;
                }
                (loc1 as Object /* flash.display.MovieClip */).play();
            }
            return;
        }

        /* internal */ /* var */_loadTips: string;

        /* internal */ /* var */_notVipTips: string;

        /* internal */ /* var */_dicFaceMcNumber: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_classDict: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_tfNotHaveFace: Object /* flash.text.TextField */;

        /* internal */ /* var */_tabBarData: Array<any>;

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_normalPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_vipPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_faceList: GTileList;

        /* internal */ /* var */_maskSp: Object /* flash.display.Sprite */;
    }
